package com.ruoyi.admin.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.admin.domain.IstGoods;
import com.ruoyi.admin.service.IIstGoodsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测试hhh商品Controller
 * 
 * @author ruoyi
 * @date 2021-01-25
 */
@Controller
@RequestMapping("/istgoods/goods")
public class IstGoodsController extends BaseController
{
    private String prefix = "istgoods/goods";

    @Autowired
    private IIstGoodsService istGoodsService;

    @RequiresPermissions("istgoods:goods:view")
    @GetMapping()
    public String goods()
    {
        return prefix + "/goods";
    }

    /**
     * 查询测试hhh商品列表
     */
    @RequiresPermissions("istgoods:goods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IstGoods istGoods)
    {
        startPage();
        List<IstGoods> list = istGoodsService.selectIstGoodsList(istGoods);
        return getDataTable(list);
    }

    /**
     * 导出测试hhh商品列表
     */
    @RequiresPermissions("istgoods:goods:export")
    @Log(title = "测试hhh商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IstGoods istGoods)
    {
        List<IstGoods> list = istGoodsService.selectIstGoodsList(istGoods);
        ExcelUtil<IstGoods> util = new ExcelUtil<IstGoods>(IstGoods.class);
        return util.exportExcel(list, "goods");
    }

    /**
     * 新增测试hhh商品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存测试hhh商品
     */
    @RequiresPermissions("istgoods:goods:add")
    @Log(title = "测试hhh商品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IstGoods istGoods)
    {
        return toAjax(istGoodsService.insertIstGoods(istGoods));
    }

    /**
     * 修改测试hhh商品
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        IstGoods istGoods = istGoodsService.selectIstGoodsById(id);
        mmap.put("istGoods", istGoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存测试hhh商品
     */
    @RequiresPermissions("istgoods:goods:edit")
    @Log(title = "测试hhh商品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IstGoods istGoods)
    {
        return toAjax(istGoodsService.updateIstGoods(istGoods));
    }

    /**
     * 删除测试hhh商品
     */
    @RequiresPermissions("istgoods:goods:remove")
    @Log(title = "测试hhh商品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(istGoodsService.deleteIstGoodsByIds(ids));
    }
}
